﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;
using System.Xml;

namespace iLangl.Model
{
	public class WorkareaRequestContext : BaseContext
	{
		IList<WorkArea> workareas = null;

		
		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (!(context is IList<WorkArea>))
			{
				throw new FormatException("Wrong context.");
			}

			workareas = context as IList<WorkArea>;
		}

		public override object GetContext()
		{
			if (workareas == null)
				return string.Empty;
			startDocument();

			Write(writer);

			return endDocument();
		}

		public void Write(XmlWriter writer)
		{
			writer.WriteStartElement("WorkAreas");
			InitExtendedAttributes(writer, workareas);
			InitExtendedElements(writer, workareas);


			foreach (WorkArea term in workareas)
			{
				writer.WriteStartElement("WorkArea");
				writer.WriteAttributeString("workAreaId", term.Id);
				writer.WriteAttributeString("workAreaName", term.Name);
				writer.WriteEndElement();
			}
			writer.WriteEndElement();
		}
	}
}
